<?php
class MY_Model extends CI_Model {
	var $table;
	function __construct() {
		parent::__construct ();
		$this->load->database ();
	}
	
	function newcrud($table) {
		$this->table = $table;
	}
	
	function create($data) {
		$this->db->insert ( $this->table, $data );
	}
	
	public function read_all() {
		
		$query = $this->db->get ( $this->table );
		return $query->result ();
	}
	
	public function read_byid($id) {
		
		$query = $this->db->get_where ( $this->table, array ('id' => $id ) );
		if ($query->num_rows () > 0) {
			foreach ( $query->result_array () as $row )
				return $row;
		} else {
			return false;
		}
	}
	
	public function updata_byid($id, $data) {
		$this->db->where ( 'id', $id );
		$this->db->update ( $this->table, $data );
	
	}
	
	public function delete($id) {
		$this->db->where ( 'id', $id );
		$this->db->delete ( $this->table );
	}
}
?>